package com.ljh.mboxvidoserver.system.configurer;

import com.ljh.mboxvidoserver.system.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class LoginConfigure implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> patterns = new ArrayList<String>();
        patterns.add("/*");
        patterns.add("/images/**");
        patterns.add("/system/**");
        patterns.add("/**/*.js");
        patterns.add("/**/*.css");
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(patterns);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/system/gotoLogin");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}
